<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">


      <el-form-item label="订单号" prop="productNo" label-width="200px">
        <el-input
          v-model="queryParams.productNo"
          style="width: 100%"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="id" align="center" prop="id" />-->
      <el-table-column label="产品名称" align="center" prop="name"/>
      <el-table-column label="产品编号" align="center" prop="productNo"/>
      <el-table-column label="派单状态" align="center" prop="operatorStatus"/>
      <el-table-column label="退款状态" align="center" prop="refundStatus"/>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDetail(scope.row)"
          >查看详情
          </el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 数据详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>

      <div class="detail-box">

        <div class="detail-box-info">
          <div class="product-name">
            产品名称：{{ orderDetail.name }}
          </div>
          <div class="product-no">
            订单号：{{ orderDetail.productNo }}
          </div>
        </div>

        <template v-if="orderDetail.product !==null">
          <p>订单信息</p>
          <table style="width: 100%" border="1">
            <thead>
            <tr>
              <th>订单价格</th>
              <th>订单来源</th>
              <th>支付方式</th>
              <th>联系电话</th>
            </tr>
            </thead>
            <tbody >
            <tr style="width: 100%" >
              <td >{{ orderDetail.product.productPrice }}</td>
              <td>{{ orderDetail.product.productSource }}</td>
              <td>{{ orderDetail.product.productPay }}</td>
              <td>{{ orderDetail.product.productInfo }}</td>
            </tr>
            </tbody>
          </table>

        </template>
        <template v-if="orderDetail.refundRecord !==null">
          <p>退款记录</p>
          <table style="width: 100%" border="1">
            <thead>
            <tr>
              <th>渠道</th>
              <th>责任人</th>
              <th>操作人</th>
              <th>订单金额</th>
              <th>退款金额</th>
            </tr>
            </thead>
            <tbody >
            <tr style="width: 100%" >
              <td >{{ orderDetail.refundRecord.paymentSource }}</td>
              <td>{{ orderDetail.refundRecord.dutyName }}</td>
              <td>{{ orderDetail.refundRecord.operatorName }}</td>
              <td>{{ orderDetail.refundRecord.productPrice }}</td>
              <td>{{ orderDetail.refundRecord.refundPrice }}</td>
            </tr>
            </tbody>
          </table>

        </template>

        <template v-if="orderDetail.operatorRecord !==null">
          <p>派单记录</p>
          <table style="width: 100%" border="1">
            <thead>
            <tr>
              <th>昵称</th>
              <th>来源</th>
              <th>接待客服</th>
              <th>接单师傅</th>
              <th>完成情况</th>
            </tr>
            </thead>
            <tbody >
            <tr style="width: 100%" >
              <td >{{ orderDetail.operatorRecord.nickname }}</td>
              <td>{{ orderDetail.operatorRecord.chatSource }}</td>
              <td>{{ orderDetail.operatorRecord.receiveName }}</td>
              <td>{{ orderDetail.operatorRecord.operatorName }}</td>
              <td>{{ orderDetail.operatorRecord.status }}</td>
            </tr>
            </tbody>
          </table>

        </template>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {listOrderRecord, getOrder} from "@/api/admin/product";
import {getToken} from "@/utils/auth";
import {parseTime} from "../../../utils/ruoyi";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,

      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退款表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productNo: null,
        productInfo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        productNo: [
          {required: true, message: "订单号不能为空", trigger: "blur"}
        ],
      },
      orderDetail: {
        productNo: "4200002085202401011106391655",
        name: "UG 12.0【推荐版】",
        operatorStatus: "已派单",
        refundStatus: "已退款",
        refundRecord: {
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          id: 38,
          recordTime: null,
          paymentSource: null,
          productName: null,
          productNo: null,
          nickname: "",
          dutyName: null,
          operatorName: null,
          refundName: null,
          productPrice: null,
          refundPrice: null,
          refundTime: null,
          description: "投诉退款",
          chatSource: null
        },
        operatorRecord: {
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          id: 1,
          operatorTime: null,
          nickname: "鬼鬼",
          operatorName: null,
          productNo: null,
          productPrice: null,
          productName: null,
          chatSource: null,
          receiveName: null,
          status: "已完成"
        },
        product: {
          createBy: "admin",
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          id: 64,
          productName: "UG 12.0【推荐版】",
          productNum: 1,
          productPrice: 79.00,
          productTotal: 79.00,
          productTime: "2024-01-01",
          productNo: "4200002085202401011106391655",
          productSource: "客户端",
          productPay: "微信支付",
          productInfo: "13772089609",
          productYear: "2024",
          productMonty: "1月",
          productDay: "45292",
          deleted: null
        }
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    parseTime,
    /** 查询退款列表 */
    getList() {
      this.loading = true;
      listOrderRecord(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        recordTime: null,
        paymentSource: null,
        productName: null,
        productNo: null,
        nickname: null,
        dutyName: null,
        operatorName: null,
        refundName: null,
        productPrice: null,
        refundPrice: null,
        refundTime: null,
        description: null,
        chatSource: null,
        remark: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    /** 修改按钮操作 */
    handleDetail(row) {
      const productNo = row.productNo
      getOrder(productNo).then(response => {
        if (response.code === 200) {
          this.orderDetail = response.data
        }
        this.open = true;
        this.title = "订单详情";
      });
    }
  }
};
</script>

<style scoped lang="scss">
.detail-box {
  .detail-box-info {
    width: 100%;
    display: flex;
    gap: 50px;
  }
  table {
    border-collapse: collapse;
    width: 100%;
    table-layout: fixed;
    word-break: break-all;
    word-wrap: break-word
  }
  th,
  td {
    border: 1px solid black;
    padding: 8px;
    text-align: center;
  }
}

</style>
